package com.aaa.china.processor;

import cn.hutool.core.util.StrUtil;
import com.aaa.china.hander.AbstractChainHandler;
import com.aaa.china.params.ImportParam;
import com.aaa.exceptions.CustomException;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author : luoBo
 */
@Component
public class CheckExcelFileSuffixHandler extends AbstractChainHandler<ImportParam>  {

    @Override
    public Boolean isSuccess(ImportParam chinaParam) {
        MultipartFile file = chinaParam.getFile();
        //1、校验文件格式
        String originalFilename = file.getOriginalFilename();
        if (StrUtil.isBlank(originalFilename)) {
            throw new CustomException("文件为空");
        }
        if (!originalFilename.endsWith(".xls") && !originalFilename.endsWith(".xlsx")) {
            throw new CustomException("文件格式错误");
        }
        return true;
    }
}
